import { useTabbarStore } from '@/stores/tabbar';

export const redirect = (url: string) => {
    uni.redirectTo({ url })
}

export const navigateTo = (url: string, events, success) => {
    uni.navigateTo({ url, events, success })
}

export const navigateBack = (delta: number = 1) => {
    uni.navigateBack({ delta })
}

export const switchTab = (url: string) => {
    try {
        uni.switchTab({ url })
        const tabbarStore = useTabbarStore();
        const index = tabbarStore.tabList.findIndex(item => item.url === url)
        if (index === -1) {
            return
        }
        tabbarStore.setTabIndex(index);
    } catch (error) {

    }
}